﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;

namespace Nyx.Scenes
{
    using XRectangle = Microsoft.Xna.Framework.Rectangle;

    /// <summary>
    /// A scene layer.
    /// </summary>
    public class SceneLayer
    {
        List<SceneObject> objects = new List<SceneObject>();

        /// <summary>
        /// Initializes a new instance of the <see cref="SceneLayer"/> class.
        /// </summary>
        public SceneLayer()
        {
            this.Visible = true;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SceneLayer"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        public SceneLayer(string name)
            : this()
        {
        }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="SceneLayer"/> is visible.
        /// </summary>
        /// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
        public bool Visible { get; set; }

        /// <summary>
        /// Gets the objects in the scene.
        /// </summary>
        /// <value>The objects in the scene.</value>
        public IEnumerable<SceneObject> Objects
        {
            get { return objects; }
        }

        /// <summary>
        /// Renders the layer.
        /// </summary>
        /// <param name="spriteBatch">The sprite batch.</param>
        public void Render(SpriteBatch spriteBatch)
        {
            foreach (SceneObject obj in objects)
            {
                if (obj != null)
                {
                    if (obj.Material != null)
                    {
                        // Render material
                    }
                    else
                    {
                        spriteBatch.Draw(SceneControl.PixelTexture,
                            obj.Position,
                            new XRectangle(0, 0, obj.Width, obj.Height),
                            obj.Color,
                            obj.Rotation,
                            obj.Origin,
                            obj.Scale,
                            SpriteEffects.None,
                            0f);
                    }
                }
            }
        }
    }
}
